<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script>
        $(function(){
            var pageNo=1, total=1;
            var pname="",category="";

            function doQuery(){
                $.get("projectSearch.jhtml",{pageNo:pageNo,pname:pname,category:category},function(p){
                    total=p.totalPage;

                    $("#paging #go").val(p.page);
                    $("#paging #total").text(total);

                    var t=$("#stuTab");
                    t.find("tr:gt(0)").remove();
                    $.each(p.data,function(i,d){
                        t.append("<tr><td>"+d.projectName+"</td><td>"+d.projectCategory+"</td><td>"+d.linkMan+"</td><td>"+d.mobliePhone+"</td><td>"+d.prochaseMode+"</td><td>"+d.isEvaluated+"</td><td>"+d.budget+"</td><td>"+d.address+"</td><td>"+(d.openDate==null?"":d.openDate)+"</td><td><a href='#' class='del' pid='"+d.id+"'>删除</a>  <a href='#' class='update' pid='"+d.id+"'>修改</a></td></tr>");
                    });
                },"json");
            }
            doQuery();
            //查询提交
            $("#search").click(function(){
                pageNo=1;
                pname=$("input[name=name]").val();
                category=$("input[name=category]").val();
                doQuery();
                return false;
            });
            //首页
            $("#paging a#first").click(function(){
                pageNo=1;
                doQuery();
                return false;
            });
            //前一页
            $("#paging a#prev").click(function(){
                if(pageNo<1){
                    alert("已经是首页了");
                    return false;
                }
                pageNo--;
                doQuery();
                return false;
            });
            $("#paging a#next").click(function(){
                if(pageNo>=total){
                    alert("已经是最后一页了");
                    return false;
                }
                pageNo++;
                doQuery();
                return false;
            });
            $("#paging a#last").click(function(){
                pageNo=total;

                doQuery();
                return false;
            });
            //go
            $("input#go").keyup(function(event){
                if(event.keyCode==13)//回车
                {
                    if(this.value==""||isNaN(this.value)){
                        return false;
                    }
                    if($(this).val()<1||$(this).val()>total){
                        // alert("没有此页1");
                        return false;
                    }
                    pageNo=$(this).val();
                    doQuery();
                }
            }).blur(function(){
                if(this.value==""||isNaN(this.value)){
                    return false;
                }
                if($(this).val()<1||$(this).val()>total){
                    // alert("没有此页2");
                    return false;
                }
                pageNo=$(this).val();
                doQuery();
            });
            $("#stuTab").on("click",".del",function(){

                var pid=$(this).attr("pid");//$(this).parent().parent().find("td:eq(0)").text();
                alert("del:"+pid);
                $.get("delProject.jhtml",{pid:pid},function (p) {
                    alert(p.msg);
                    doQuery();
                },"json");
                return false;
            });
            $("#stuTab").on("click",".update",function(){
                var pid=$(this).attr("pid");
                window.location="updateProject.html?pid="+pid;
                //location.search   ?45
                return false;
            });
        });
    </script>
</head>
<body>
<h2>项目信息</h2>
<p>
<form method="get" action="users.html" id="searchForm">
    <input type="search" name="name" placeholder="项目名称"/>
    <input type="search" name="category" placeholder="项目类型"/>
    <input type="submit" value="search" id="search"/>
</form>
</p>
<table border="1" cellpadding="0" cellspacing="0" id="stuTab">
    <tr>
        <td>项目名称</td><td>项目类型</td><td>项目联系人姓名</td><td>项目联系人电话</td><td>采购方式</td>
        <td>项目状态</td><td>预算</td><td>开标地点</td><td>开标时间</td>
        <td>操作</td>
    </tr>
</table>
<p align="center" id="paging">
    <a href="#" id="first">首页</a>

    <a href="#" id="prev">上一页</a>

    <input type="number" min="1" id="go" name="go" style="width:30px" value=""/>/<span id="total"></span>

    <a href="#" id="next">下一页</a>

    <a href="#" id="last">末页</a>
</p>
</body>
</html>
